import request from "@/utils/request";
import { ParamsType } from "@/api/manager/project/types";

/**
 * manager切换项目下拉列表
 */
export function getManagerAllProjectPulldown() {
  return request({
    url: "/api/v1/manager/project/pulldown",
    method: "get",
  });
}

/**
 * Corp切换项目下拉列表
 */
export function getCorpAllProjectPulldown() {
  return request({
    url: "/api/v1/corp/project/pulldown",
    method: "get",
  });
}

/**
 * constructor切换项目下拉列表
 */
export function getConstructorAllProjectPulldown() {
  return request({
    url: "/api/v1/constructor/project/pulldown",
    method: "get",
  });
}

/**
 * constructor切换项目下拉列表
 */
export function getCommanderAllProjectPulldown() {
  return request({
    url: "/api/v1/commander/project/pulldown",
    method: "get",
  });
}

/**
 * Manager切换项目调用
 * @param id
 */
export function changeManagerCurrentProject(id: any) {
  return request({
    url: "/api/v1/manager/common/projectChanges/" + id,
    method: "put",
  });
}

/**
 * Corp切换项目调用
 * @param id
 */
export function changeCorpCurrentProject(id: any) {
  return request({
    url: "/api/v1/corp/common/projectChanges/" + id,
    method: "put",
  });
}

/**
 * Corp切换项目调用
 * @param id
 */
export function changeConstructorCurrentProject(id: any) {
  return request({
    url: "/api/v1/constructor/common/projectChanges/" + id,
    method: "put",
  });
}

/**
 * 指挥部切换项目调用
 * @param id
 */
export function changeCommanderCurrentProject(id: any) {
  return request({
    url: "/api/v1/commander/common/projectChanges/" + id,
    method: "put",
  });
}

/**
 * 建设单位下拉
 */
export function constructor_pulldown() {
  return request({
    url: "/api/v1/common/constructor_pulldown",
    method: "get",
  });
}

/**
 * 监管单位下拉
 */
export function getDeptPullDown(data: any) {
  return request({
    url: "/api/v1/common/getDeptPullDown",
    method: "get",
    params: data,
  });
}

/**
 * 指挥部下拉
 */
export function getCommanderPullDown(constructorId: any) {
  return request({
    url: "/api/v1/common/commanders_pulldown/" + constructorId,
    method: "get",
    params: { pageIndex: 1, pageSize: 9999 },
  });
}

/**
 * 未登记项目下拉
 */
export function noRegisterProjects(corpId: number) {
  return request({
    url: `/api/v1/common/noRegisterProjects`,
    method: "get",
    params: { corpId: corpId, pageIndex: 1, pageSize: 9999 },
  });
}

/** 根据施工企业获取为登记项目分页 */
export function getProjectByCorpIdWithUnregistered(data: ParamsType) {
  return request({
    url: `api/v1/common/noRegisterProjects`,
    method: "get",
    params: data,
  });
}

/** 根据项目id获取现场管理人员 */
export function GetWorksiteManager(projectId: any) {
  return request({
    url: `api/v1/common/worksite_manager/` + projectId,
    method: "get",
  });
}

/** 获取项目下拉列表 */
export function GetProjectPulldown() {
  return request({
    url: `api/v1/sysuser/project/pulldown`,
    method: "get",
  });
}

/** 获取企业下拉列表 */
export function GetCorpsPulldown(data?: any) {
  return request({
    url: `api/v1/common/corps_pulldown`,
    method: "get",
    params: data,
  });
}

/** 获取企业下拉列表 */
export function GetGroupPulldown(data?: any) {
  return request({
    url: `api/v1/common/group_pulldown`,
    method: "get",
    params: data,
  });
}

/**查询项目列表 */
export function QueryProjectList(data: any) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/project/project_page`;
      break;
    case "Corp":
      url = `/api/v1/corp/project/project_page`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/project/project_page`;
      break;
    case "Manager":
      url = `/api/v1/manager/project/project_page`;
      break;
    case "Commander":
      url = `/api/v1/commander/project/project_page`;
      break;
    default:
      url = `/api/v1/sysuser/project/project_page`;
  }
  return request({
    url: url,
    method: "get",
    params: data,
  });
}

/**获取审核失败的项目 */
export function GetFailProjectForm(editToken: string) {
  return request({
    url: `/api/v1/auth/failproject/${editToken}/form`,
    method: "get",
  });
}

/**重新提交审核失败的项目 */
export function FailProjectreSubmit(data: any) {
  return request({
    url: `/api/v1/auth/failprojectresubmit`,
    method: "put",
    data: data,
  });
}
